﻿using System;
using System.Collections.Generic;
using System.Linq;
using ExpenseSystem.Common;
using ExpenseSystem.Fether;
using ExpenseSystem.Lor;
using ExpenseSystem.Model;

namespace ExpenseSystem.Fether
{
    public class RoleUserFetcher:SystemFetcher<RoleUserModel>,IDetailSystemFetcher<RoleUserModel>
    {
        public IList<RoleUserModel> ListByUserId(long userid,out string message,out int rows)
        {
            IList<RoleUserModel> result = List( OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("UserId", userid).And(Restrain.Eq("Avaliable",true)));
            return result;
        }
        public IList<RoleUserModel> ListByRoleId( long roleId, out string message,out int rows)
        {
            IList<RoleUserModel> result = List( OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("RoleId", roleId).And(Restrain.Eq("Avaliable", true)));
            return result;
        }
        public RoleUserModel GetByRoleIdAndUserId( long roleId, long user, out string message, out int rows)
        {
            IList<RoleUserModel> result = List(OrderBy.GetDefault(), Limit.GetDefault(), out message,  out  rows,Restrain.Eq("UserId", user).And(Restrain.Eq("RoleId", roleId)).And(Restrain.Eq("Avaliable", true)));
            if (result.Count > 0)
                return result.First();
            return null;
        }

        public IList<RoleUserModel> ListByMainId( long mainId, out string message,out int rows)
        {
            return ListByRoleId(mainId,out message,out rows);
        }
    }
}
